﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.SharePoint.Administration;
using System.Windows;

namespace SharePointCommander.Model.TreeView
{
    public class SCSolutionCollection : SCTreeViewItem<SPSolutionCollection>
    {
        public SCSolutionCollection(SCTreeViewItem parent, SPSolutionCollection solutions)
            : base(parent, solutions)
        {
            Header = "Solutions";
            Expanded += new RoutedEventHandler(SCSolutionCollection_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCSolutionCollection_Expanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = e.Source as TreeViewItem;
            if (!item.ItemsSource.OfType<SCSolution>().Any())
            {
                item.ItemsSource = from s in SPObject select new SCSolution(this, s) as TreeViewItem;
            }
        }
    }
}
